<template>
    <div class="container">
        <el-row>
            <el-form ref="form" :model="form" label-width="100px">
                <el-form-item label="类型" prop="type">
                    <el-input style="width: 250px" placeholder="员工" disabled></el-input>
                </el-form-item>
                <el-form-item label="客户姓名：" prop="name" :rules="[{ required: true, message: '客户姓名不能为空' }]">
                    <el-input style="width: 250px" v-model="form.name" @input="handleName" placeholder="请输入客户姓名"></el-input>
                </el-form-item>
                <el-form-item label="电话：" prop="phone" :rules="[{ required: true, message: '电话不能为空' }]">
                    <el-input style="width: 250px" maxlength="11" v-model="form.phone" @input="handlePhone" placeholder="请输入电话"></el-input>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="onSubmit('form')" :loading="loading">保存</el-button>
                </el-form-item>
            </el-form>
        </el-row>
    </div>
</template>

<script>
    import normalFilter from "@/components/NormalFilter";
    import Upload from "@/components/UploadFile";
    import Tinymce from "@/components/Tinymce";
    import { Message } from "element-ui";
    import { add } from "@/api/signIn";
    import { imgTypeArr } from "@/utils/enumConfig";

    export default {
        name: "SignInAdd",
        components: {
            normalFilter,
            Tinymce,
            Upload,
        },
        data() {
            return {
                loading: false,
                imgType: imgTypeArr.join(","),
                form: {
                    type:'staff',
                    name: "",
                    phone: "",
                },
            };
        },
        mounted() {
            //   tinymce.init({})
        },
        methods: {
            handleName(val) {
                this["form"]["name"] = val;
            },
            handlePhone(val) {
                this["form"]["phone"] = val;
            },
            onSubmit(formName) {
                const { validate } = this.$refs[formName];
                validate((valid) => {
                    if (valid) {
                        this._submitData(this.form);
                    }
                });
            },
            fileListChange(arr) {
                if (arr.length === 0) {
                    this["form"]["coverUrl"] = "";
                } else {
                    this["form"]["coverUrl"] = arr[0]["url"];
                    this.$refs.img.clearValidate();
                }
            },
            bannerChange(arr) {
                if (arr.length === 0) {
                    this["form"]["bannerUrl"] = "";
                } else {
                    this["form"]["bannerUrl"] = arr[0]["url"];
                    this.$refs.img.clearValidate();
                }
            },
            async _submitData(params) {
                this.loading = true;
                let res = await add(params);
                this.loading = false;
                if (res.code === 1) {
                    Message({
                        message: "保存成功！",
                        type: "success",
                        duration: 1 * 1000,
                    });
                    setTimeout(() => {
                        this.$router.go(-1);
                    }, 1000);
                }
            },
        },
    };
</script>

<style lang="scss" scoped>
    .container {
        width: 100%;
        height: 100%;
        padding: 20px;
        .radio-form {
            ::v-deep .el-form-item__error {
                left: 5%;
            }
        }
    }
</style>
